﻿

$(function () {
    fantian();
})
function fantian() {
    // 发送AJAX请求获取数据
    console.log(localStorage.getItem("ProductionPlanId"))
            $.ajax({
                type: "get",
                url: "/Productionplanning/ByidPro",
                data: {
                    ProductionPlanId: localStorage.getItem("ProductionPlanId"),
                    token: localStorage.getItem("token")
                },
                success: function (res) {
                    var ter = JSON.parse(res)
                    console.log(ter.Data)

                    $(ter.Data).each(function () {
                        $('#ProductionPlanNumber').val(this.ProductionPlanNumber);
                        $('#Id').val(this.Id);
                        $('#ProductNumber').val(this.ProductNumber);
                        $('#FinishedProductSpecification').val(this.FinishedProductSpecification);
                        $('#ProcessNo').val("10mm");
                        $('#PlannedProduction').val(this.PlannedProduction);
                        $('#ProcessRouteName').val(this.ProcessRouteName);
                        localStorage.setItem("idss", this.ProductionPlanId);
                       
                    })
                  
                },
               
            });
         
    
}
var obj1 = {
    ProductionPlanId: "",
    StartingDate: "",
    EndingDate: "",
    ProductionStatus:""
}
layui.use(function () {
    var $ = layui.$;
    var layer = layui.layer;
    var util = layui.util;
    var form = layui.form;
    var table = layui.table;

    //修改采购信息
    form.on('submit(formSubmit)', function (data) {
        var field = data.field;
        var checkStatus = table.checkStatus('allUpdateP');
        field.allocationProdutesList = checkStatus.data.map(function (item) {
            return item;
        });
        console.log(field)
        obj1.ProductionPlanId = localStorage.getItem("idss")
        obj1.StartingDate = $("#CreatedDatesss").val()
        obj1.EndingDate = $("#EndDatesss").val()
        obj1.ProductionStatus="已排程"
        console.log(obj1);//field.products
        // 显示填写结果，仅作演示用
        $.ajax({
            url: '../Productionplanning/UpdateProcessPlan',
            type: 'post',
            data: {
                model: obj1,
                token: localStorage.getItem("token"),
            },
            success: function (res) {
                var res = JSON.parse(res)
                console.log(obj1);
                console.log(res);
                if (res.Code > 0) {
                    layer.alert("排程成功");
                    location.href = '/Productionplanning/ShowProductionplanning'
                } else {
                    layer.alert("排程失败");
                }
            }
        });

        return false; // 阻止默认 form 跳转
    });

});



